import re
import pandas as pd
class LengthTransition:
    def __init__(self):
        self.unit_1=''
        self.unit_2=''
        self.ans=''
    def transition(self,num:str):
        series_meters=pd.Series([1000,1,0.1,0.01,0.001,0.0254,0.3048],index=['km','m','dm','cm','mm','in','ft'])
        if self.unit_1 not in series_meters or self.unit_2 not in series_meters:
            self.ans='0'
        else:
            if num.isdigit():
                num=float(num)
            value_to_meters=num*series_meters[self.unit_1] #先转换为米再转换为其他单位
            self.ans=value_to_meters/series_meters[self.unit_2]
            self.ans=round(self.ans,7)
        return str(self.ans)
    def setUnit_1(self,strs:str):
        self.unit_1=re.findall(r'[a-z]+',strs)[0]
    def setUnit_2(self,strs:str):
        self.unit_2=re.findall(r'[a-z]+',strs)[0]